// Package _range layer_range
// @Title _range
// @Description
// @Author  == 琳琳也叫王木木 ==  2021/9/1 17:49
// @Create  2021/9/1 17:49
package _range

import "go_leetcode/special_practice/3_tree"

// LayerRange 使用队列实现层序遍历的打印一棵树
func LayerRange(root *__tree.MyTreeNode) []int {
	ans := make([]int, 0)
	if root == nil {
		return ans
	}
	queue := []*__tree.MyTreeNode{root}
	for len(queue) > 0 {
		// 从队列中弹出一个元素
		temp := queue[0]
		queue = queue[1:]
		ans = append(ans, temp.Val)
		if temp.Left != nil {
			queue = append(queue, temp.Left)
		}
		if temp.Right != nil {
			queue = append(queue, temp.Right)
		}
	}
	return ans
}
